package nccloud.utils.baseapp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import nc.vo.pub.lang.UFDate;

public class GetDateUtil {
	/**
	 * 通过当前日期   获取本月日期第一天
	 * @param date
	 * @return yyyy-MM-dd
	 */
	public static String getCurrentFistDay(UFDate date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date.toDate());
		calendar.add(Calendar.MONTH, 0);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
//		calendar.set(Calendar.HOUR_OF_DAY, 00);
//		calendar.set(Calendar.MINUTE, 00);
//		calendar.set(Calendar.SECOND, 00);
		Date lastMonth = calendar.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(lastMonth);
	}
	/**
	 * 通过当前日期   获取本月日期最后一天
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String getCurrentLastDay(UFDate date) {
		Calendar calendars = Calendar.getInstance();
		calendars.setTime(date.toDate());
		int month = calendars.get(Calendar.MONTH);
		calendars.set(Calendar.MONTH, month);
		calendars.set(Calendar.DAY_OF_MONTH,
				calendars.getActualMaximum(Calendar.DAY_OF_MONTH));
		calendars.set(Calendar.HOUR_OF_DAY, 23);
		calendars.set(Calendar.MINUTE, 59);
		calendars.set(Calendar.SECOND, 59);
		Date lastMonths = calendars.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(lastMonths);
	}

	/**
	 * 通过当前日期   获取上月日期第一天
	 * @param date
	 * @return yyyy-MM-dd
	 */
	public static String getFistDay(UFDate date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date.toDate());
		calendar.add(Calendar.MONTH, -1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 00);
		calendar.set(Calendar.MINUTE, 00);
		calendar.set(Calendar.SECOND, 00);
		Date lastMonth = calendar.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(lastMonth);
	}
	/**
	 * 通过当前日期   获取上月日期最后一天
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String getLastDay(UFDate date) {
		Calendar calendars = Calendar.getInstance();
		calendars.setTime(date.toDate());
		int month = calendars.get(Calendar.MONTH);
		calendars.set(Calendar.MONTH, month - 1);
		calendars.set(Calendar.DAY_OF_MONTH,
				calendars.getActualMaximum(Calendar.DAY_OF_MONTH));
		calendars.set(Calendar.HOUR_OF_DAY, 23);
		calendars.set(Calendar.MINUTE, 59);
		calendars.set(Calendar.SECOND, 59);
		Date lastMonths = calendars.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(lastMonths);
	}
}
